var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "goodsName",
			name : "商品名称",
			isSort:true,
		},{
			colkey : "consultContent",
			name : "咨询内容",
			isSort:true,
		},{
			colkey : "creater",
			name : "咨询人",
			isSort:true,
		}, {
			colkey : "type",
			name : "类型",
			renderData :function(rowindex ,data, rowdata, colkey){
				 //rowindex 当前行号 ,data 当前列的数据 ,rowdata 当前行json数据, colkey 当前列的colkey
               //处理当前列数据。可自定义html
				if(data=='1'){
					return "咨询";
				}else{
					return "否";
				}
			}
		},{
			colkey : "status",
			name : "状态",
			renderData :function(rowindex ,data, rowdata, colkey){
				//rowindex 当前行号 ,data 当前列的数据 ,rowdata 当前行json数据, colkey 当前列的colkey
				//处理当前列数据。可自定义html
				if(data=='1'){
					return "<span style='color:green'>已回复</span>";
					
				}else if(data=='2'){
					return "<span style='color:red'>未回复</span>";
				}
			}
		},{
			colkey : "replyContent",
			name : "回复内容",
		}, {
			colkey : "createTime",
			name : "创建时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd");
			}
		}, {
			name : "操作",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				return "<button type='button' onclick='messageReply("+rowdata.id+");' value='"+rowdata.id+"' class='btn btn-info marR10'>回复</button>";
			}
		} ],
		jsonUrl : rootPath + '/messageReply/selectMessageReply',
		checkbox : true,
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	
	/***
	 * 回复触发事件
	 */
	/*$("button").click(function(){
		//  $("p").slideToggle();
		  alert($(this).val());
		  var replyID = $(this).val();
		  pageii = layer.open({
				title : "咨询回复",
				type : 2,
				area : [ "800px", "90%" ],
				content : rootPath + '/messageReply/replyMessage?id='+replyID
		  });
	});*/
	
	$("#addMessageReply").click("click", function() {
		addMessageReply();
	});
	$("#message_reply").click("click", function() {
		messageReply();
	});
	$("#delMessageReply").click("click", function() {
		delMessageReply();
	});
	
});

//回复用户咨询信息
function messageReply(id) {
	// var replyID = $(this).val();
	  pageii = layer.open({
			title : "咨询回复",
			type : 2,
			area : [ "650px", "75%" ],
			content : rootPath + '/messageReply/replyMessage?id='+id
	  });
}
function addMessageReply() {
	pageii = layer.open({
		title : "新增",
		type : 2,
		area : [ "800px", "90%" ],
		content : rootPath + '/messageReply/addMessageReply'
	});
}
function delMessageReply() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/messageReply/delMessageReply';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}